﻿namespace Sgr.Generator.Segment
{
    /// <summary>
    /// 号段生成器配置项
    /// </summary>
    public class SegmentNumIdGeneratorOptions
    {
        /// <summary>
        /// 号段所在数据库名称
        /// </summary>
        public string DatabaseName { get; set; } = string.Empty;

        /// <summary>
        /// 最大步长，不可小于100
        /// </summary>
        public int MaxStepUpperBound { get; set; } = 20000;

        /// <summary>
        /// 动态步长计算的最小下限，防止步长过小导致频繁数据库扩容。默认 100，不可小于100
        /// </summary>
        public int MinStepLowerBound { get; set; } = 100;

        /// <summary>
        /// 号段维持时间(毫秒)
        /// </summary>
        public long SegmentDuration { get; set; } = 15 * 60 * 1000L;

        /// <summary>
        /// 获取读写锁超时时间(毫秒)，推荐 50 ~ 150
        /// </summary>
        public int BufferRwTimeout { get; set; } = 80;

        /// <summary>
        /// 慢路径下，获取ID尝试次数上限，推荐 256 ~ 1024
        /// </summary>
        public int GetId_Attempt_Limit { get; set; } = 512;

        /// <summary>
        /// 慢路径下，获取ID超时时间(毫秒)，推荐 1000 ~ 3000
        /// </summary>
        public int GetId_TimeOut_Milliseconds { get; set; } = 2000;

        /// <summary>
        /// 从数据库更新号段尝试次数上限，推荐：800 ~ 3000。默认 2000。
        /// </summary>
        public int UpdateSegmentFromDb_TimeOut_Milliseconds { get; set; } = 2000;

        /// <summary>
        /// 触发熔断器后的恢复时间（秒）
        /// </summary>
        public int Circuit_Reset_Seconds { get; set; } = 30;

        /// <summary>
        /// 触发熔断器的错误阈值
        /// </summary>
        public int ErrorThresholdBeforeTrip { get; set; } = 3;

        /// <summary>
        /// 更新间隔（秒）
        /// </summary>
        public int UpdateIntervalSeconds { get; set; } = 0;
    }
}